using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;

using System.Data;

namespace Business
{
    public class KhachHangService
    {




		//////////////////////////////////////////////////////////

 		                                                         

		//            Enter code your here                      //

		                                                         

		//////////////////////////////////////////////////////////

       static public DataTable ConvertListKhachHangDTOToDataTable( List<KhachHangDTO> lst)
       {
               DataTable dt = new DataTable();
           dt.Columns.Add( "MaKhachHang");
           dt.Columns.Add( "HoTen");
           dt.Columns.Add( "MaLoaiKhachHang");
           dt.Columns.Add( "CMND");
           dt.Columns.Add( "DiaChi");
           dt.Columns.Add( "DanhNghia");
           for( int i = 0; i < lst.Count; i ++)
           {
               dt.Rows.Add(
                       lst[i].MaKhachHang,      
                       lst[i].HoTen,      
                       lst[i].MaLoaiKhachHang,      
                       lst[i].CMND,      
                       lst[i].DiaChi,      
                       lst[i].DanhNghia      
                   );
           }
               return dt;
       }
        static public int GetIdentity()
        {
            Data.KhachHangRepository repo = new KhachHangRepository();
            return repo.GetIdentity();
        }

        static public int Count()
        {
            return KhachHangRepository.Count();
        }
        public static bool Them(KhachHangDTO objDTO)
        {
                KhachHangRepository repo = new KhachHangRepository();
                return repo.Them(objDTO);
        }

        public static bool Xoa(int MaKhachHang, bool XoaKhoaNgoai=false)
        {
              KhachHangRepository Repo = new KhachHangRepository();
              return Repo.Xoa(MaKhachHang,XoaKhoaNgoai);
        }

        public static void CapNhat(KhachHangDTO objDTO)
        {
            try
            {
                KhachHangRepository Repo = new KhachHangRepository();
                Repo.CapNhat(objDTO);
            }
            catch (System.Exception )
            {
            }
        }

        public static List<KhachHangDTO> LayDanhSach()
        {
            List<KhachHangDTO> lst = new List<KhachHangDTO>();
            try
            {
                KhachHangRepository obj = new KhachHangRepository();
                lst = obj.LayDanhSach();
            }
            catch (System.Exception )
            {
            }
            return lst;
        }

        static public List<KhachHangDTO> LayDanhSach(int Start, int Record)
        {
             Data.KhachHangRepository repo = new KhachHangRepository();
            return repo.LayDanhSach(Start, Record);
        }

        public static KhachHangDTO LayTheoMa(int MaKhachHang)
        {
            KhachHangDTO objDTO = new KhachHangDTO();
            try
            {
                KhachHangRepository Repo = new KhachHangRepository();
                objDTO = Repo.LayTheoMa(MaKhachHang);
            }
            catch (System.Exception )
            {
            }
            return objDTO;
        }

//
//Khoa ngoai LoaiKhachHang
//
        static public List<KhachHangDTO> LayDanhSachTheoMaLoaiKhachHang( int MaLoaiKhachHang)
        {
             Data.KhachHangRepository repo = new KhachHangRepository();
            return repo.LayDanhSachTheoMaLoaiKhachHang( MaLoaiKhachHang);
        }

        static public void XoaTheoMaLoaiKhachHang( int MaLoaiKhachHang, bool XoaKhoaNgoai=false)
        {
             Data.KhachHangRepository repo = new KhachHangRepository();
            repo.XoaTheoMaLoaiKhachHang( MaLoaiKhachHang,XoaKhoaNgoai);
        }

    }
}

